require File.dirname(__FILE__)+"/../test_helper"
require "starframe"
require "starframe/loadable"

class TestStarFrameLoadable < Test::Unit::TestCase
  module TestPostfixesAndLoaded
    extend StarFrame::Loadable
    @@postfixes = [".png"]
    
    def self.loaded path
      StarRuby::Texture.load path
    end
  end
  
  module TestPostFixes
    extend StarFrame::Loadable
    @@postfixes = [".wav"]
  end
  
  module TestLoaded
    extend StarFrame::Loadable
    
    def self.loaded path
      path
    end
  end
  
  def test_load
    assert_equal [], TestPostfixesAndLoaded.constants
    TestPostfixesAndLoaded.load(File.dirname(__FILE__)+"/../app/images")
    assert_equal ["Dir", "Star"], TestPostfixesAndLoaded.constants.sort
    assert_equal ["Star"],        TestPostfixesAndLoaded::Dir.constants
    
    assert_instance_of StarRuby::Texture, TestPostfixesAndLoaded::Star
    assert_instance_of Module,            TestPostfixesAndLoaded::Dir
    assert_instance_of StarRuby::Texture, TestPostfixesAndLoaded::Dir::Star
    
    assert_equal File.dirname(__FILE__)+"/../app/images/star.png",     TestPostfixesAndLoaded::Star.path
    assert_equal File.dirname(__FILE__)+"/../app/images/dir/star.png", TestPostfixesAndLoaded::Dir::Star.path
    
    
    assert_equal [], TestPostFixes.constants
    TestPostFixes.load(File.dirname(__FILE__)+"/../app/images")
    assert_equal ["Dir"], TestPostFixes.constants
    assert_equal [],      TestPostFixes::Dir.constants
    
    
    assert_equal [], TestLoaded.constants
    TestLoaded.load(File.dirname(__FILE__)+"/../app/images")
    assert_equal ["Dir", "Star", "Text"], TestLoaded.constants.sort
    assert_equal ["Star"],                TestLoaded::Dir.constants
    
    assert_instance_of String, TestLoaded::Star
    assert_instance_of String, TestLoaded::Text
    assert_instance_of Module, TestLoaded::Dir
    assert_instance_of String, TestLoaded::Dir::Star
    
    assert_equal File.dirname(__FILE__)+"/../app/images/star.png",     TestLoaded::Star
    assert_equal File.dirname(__FILE__)+"/../app/images/text.txt",     TestLoaded::Text
    assert_equal File.dirname(__FILE__)+"/../app/images/dir/star.png", TestLoaded::Dir::Star
  end
end

#from dispatcher (scene loader)
    # @base_dir = File.expand_path("../app", File.dirname(__FILE__))
=begin
  def test_initialize
    assert_equal({:main     => ["#{@base_dir}/scenes/main_scene.rb",     :MainScene], 
                  :sub_game => ["#{@base_dir}/scenes/sub_game_scene.rb", :SubGameScene]}, @dispatcher.scenes)
  end
  
  def test_scene
    scene = @dispatcher.scene(:main)
    assert_kind_of MainScene, scene
    assert $".any?{ |path| /\/main_scene.rb$/ === path}
  end
=end